package database

import (
	"hxy/repo/cmd"
	"time"

	"gorm.io/gorm"
)

// # region pipelinetask
func CreatePipelineTask(task cmd.PipelineTask) (tx *gorm.DB) {
	task.BeginTime = time.Now()
	return Db.Create(&task)
}
func DeletePipelineTask(uuid string) (tx *gorm.DB) {
	return Db.Delete(&cmd.PipelineTask{}, uuid)
}
func ChangePipelineState(task cmd.PipelineTask, staus string) (tx *gorm.DB) {
	return Db.Model(&task).Update("state", staus)
}
func AddTaskEndtiem(task cmd.PipelineTask) (tx *gorm.DB) {
	task.EndTime = time.Now()
	return Db.Model(&task).Update("end_time", task.EndTime)
}
func FindPipelineTask(uuid string) (task cmd.PipelineTask, re *gorm.DB) {
	re = Db.Where("ID = ?", uuid).Find(&task)
	return task, re
}
func GetAllPipeline() []cmd.PipelineTask {
	var list []cmd.PipelineTask
	Db.Find(&list)
	return list
}
func GetAllPipelinebyGitid(gitid int) []cmd.PipelineTask {
	var list []cmd.PipelineTask
	Db.Where("git_id = ?", gitid).Find(&list)
	return list
}

//#endregion
